package com.xy.user.service.impl;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

import com.ruoyi.common.core.domain.user.Skill;
import com.ruoyi.common.core.mapper.user.SkillMapper;
import com.xy.user.service.ISkillService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 技能Service业务层处理
 *
 * @author ruoyi
 * @date 2025-05-29
 */
@Service
public class SkillServiceImpl implements ISkillService {
    @Autowired
    private SkillMapper skillMapper;

    /**
     * 查询技能
     *
     * @param id 技能主键
     * @return 技能
     */
    @Override
    public Skill selectSkillById(String id) {
        return skillMapper.selectSkillById(id);
    }

    /**
     * 查询技能列表
     *
     * @param skill 技能
     * @return 技能
     */
    @Override
    public List<Skill> selectSkillList(Skill skill) {
        return skillMapper.selectSkillList(skill);
    }

    /**
     * 新增技能
     *
     * @param skill 技能
     * @return 结果
     */
    @Override
    public int insertSkill(Skill skill) {
        return skillMapper.insertSkill(skill);
    }

    /**
     * 修改技能
     *
     * @param skill 技能
     * @return 结果
     */
    @Override
    public int updateSkill(Skill skill) {
        return skillMapper.updateSkill(skill);
    }

    /**
     * 批量删除技能
     *
     * @param ids 需要删除的技能主键
     * @return 结果
     */
    @Override
    public int deleteSkillByIds(String[] ids) {
        return skillMapper.deleteSkillByIds(ids);
    }

    /**
     * 删除技能信息
     *
     * @param id 技能主键
     * @return 结果
     */
    @Override
    public int deleteSkillById(String id) {
        return skillMapper.deleteSkillById(id);
    }

    @Override
    public List<Skill> getSkill(String skills) {
        try {
            String[] split = skills.split(",");
            return Arrays.stream(split).map(skill -> skillMapper.selectSkillById(skill)).collect(Collectors.toList());
        } catch (Exception e) {
            System.err.println("根據ids獲取skill對象異常");
            throw new RuntimeException("根据ids獲取skill對象異常" + e);
        }
    }
}
